package cn.edu.hrbcu.es.invigilatemanagerment.service;

import cn.edu.hrbcu.es.invigilatemanagerment.dao.RolePermissionMapper;
import cn.edu.hrbcu.es.invigilatemanagerment.pojo.RoleExample;
import cn.edu.hrbcu.es.invigilatemanagerment.pojo.RolePermission;
import cn.edu.hrbcu.es.invigilatemanagerment.pojo.RolePermissionExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.hibernate.criterion.Example;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RolePermissionServiceImpl implements IRolePermissionService{
    @Autowired
    private RolePermissionMapper rolePermissionMapper;
    @Override
    public Integer insertRolePermission(RolePermission rolePermission) {
        return rolePermissionMapper.insert(rolePermission);
    }

    @Override
    public Integer deleteRolePermissionByPrimaryId(Integer roleId) {
        return rolePermissionMapper.deleteByPrimaryKey(roleId);
    }

    @Override
    public Integer updateRolePermissionByPrimaryId(RolePermission rolePermission) {
        return rolePermissionMapper.updateByPrimaryKey(rolePermission);
    }

    @Override
    public List<RolePermission> queryRolePermissionsByIds(List<Integer> ids) {
        return null;
    }

    @Override
    public RolePermission queryRolePermissionsById(Integer id) {
        return rolePermissionMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<RolePermission> queryAllRolePermission() {
        RolePermissionExample example = new RolePermissionExample();
        RolePermissionExample.Criteria criteria = example.createCriteria();
        criteria.getAllCriteria();
        return rolePermissionMapper.selectByExample(example);
    }

    @Override
    public List<RolePermission> queryRolePermissionByPage(int pageNow, int pageSize) {
        PageHelper.startPage(pageNow,pageSize);
        List<RolePermission> rolePermissions = this.queryAllRolePermission();
        PageInfo<RolePermission> rolePermissionsPageInfo = new PageInfo<>(rolePermissions);
        return rolePermissionsPageInfo.getList();
    }

    @Override
    public int queryRolePermissionCount() {
        RolePermissionExample rolePermissionExample = new RolePermissionExample();
        RolePermissionExample.Criteria criteria = rolePermissionExample.createCriteria();
        criteria.getAllCriteria();
        return (int) rolePermissionMapper.countByExample(rolePermissionExample);
    }
}
